﻿using Sessionizer.Samples.Model;
using Sessionizer.Samples.Sessionized.Rankers.NameLength;

namespace Sessionizer.Samples.Sessionized.Rankers.Database
{
    /// <summary>
    /// Has dependency to other Ranker and external component/
    /// </summary>
    public sealed class DatabaseRanker : IRanker
    {
        private readonly IDatabase _database;
        private readonly NameLengthRanker _nameLengthRanker;

        /// <summary>
        /// Resolves dependencies
        /// </summary>
        /// <param name="database">External component</param>
        /// <param name="nameLengthRanker">Other ranker</param>
        public DatabaseRanker(
            IDatabase database,
            NameLengthRanker nameLengthRanker
            )
        {
            _database = database;
            _nameLengthRanker = nameLengthRanker;
        }

        public int Rank(ITeam team)
        {
            var nlRank = _nameLengthRanker.Rank(team);
            if (_database.IsRegistred(team))
            {
                return nlRank * 2;
            }
            return nlRank / 2;
        }
    }
}